<template>
 <view class="u-wrap">
	 <view class="u-demo-wrap">
		 
		 <view class="u-demo-title">
			 <u-avatar :src=src size="200" ></u-avatar>
		 </view>
		 <view class="u-demo-title">
		 			 <text>头像预览</text>
		 </view>
		 <view class="u-demo-title">
		 			 <u-button shape="circle" size="medium" type="primary" @click="yes">确定</u-button>
		 </view>
		 <view class="u-demo-area">
			<u-toast ref="uToast"></u-toast>

		 </view>
	 </view>
	 <view>
		 <u-grid :col="3">
			 <u-grid-item v-for="(dy,index) in dianyings" :key="dy.id">
				 <view class="image-item" @click="select(index)">
				 <view class="image-content">
					 <image style="width: 120px; height: 150px; background-color:
					#eeeeee;" mode="aspectFill"
					 :src="'../../static/头像'+index+'.jpg'" @error="imageError">
					</image>
				 </view>

			 </view>
			 </u-grid-item>
		 </u-grid>
	 </view>
 
 </view>
</template>
<script>
 export default {
	 data() {
		 return {
		 //轮播图
			src:"",
			title: true,
			mode: 'round',
			indicatorPos: 'bottomCenter',
			effect3d: false,
			//结束轮播图
			 
			//定义电影集合
			dianyings:[1,2,3,4,5,6]  //最多6张图片
		 }
	 },
 computed: {
 },


 methods: {
	 select(dyid){
		console.log("选择了第"+dyid+"张图片");
		this.src="../../static/头像"+dyid+".jpg";
	 },
	 yes(){
		 uni.request({
		 	url:"http://localhost:9090/changeUserImg?userImg="+this.src+"&userId="+getApp().globalData.globalUserid,
		 	method:"GET",
		 	success:(res)=>{
		 		if(res.data.code*1==200){
		 			this.$u.toast("修改头像成功！");	
		 		}
		 		else{
		 			this.$u.toast("修改头像失败，数据异常！");
		 		}
		        
		 	}
		 })
		 uni.navigateBack(); //退回上一页
	 },
	 imageError() {
		
	 },
},

	
}
</script>
<style scoped lang="scss">
 @import "@/common/demo.scss"; 
	 .u-demo-title{
		
		background: "#ffff00";
	 }
</style>